package com.sharker.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.sharker.R;
import com.sharker.models.Course;

import java.util.ArrayList;
import java.util.List;

/**
 * 项目名称：MyApplication2
 * 类描述：
 * 创建人：${徐家浩}
 * 创建时间：2017/4/7 13:54
 * 修改人：${徐家浩}
 * 修改时间：2017/4/7 13:54
 * 修改备注：
 */
public class KechengAdapter extends RecyclerView.Adapter<KechengAdapter.Kechengholder> {
    private Context context;
    private List<Course> list=new ArrayList<>();

    public KechengAdapter(Context context, List<Course> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public Kechengholder onCreateViewHolder(ViewGroup parent, int viewType) {
        Kechengholder kechengholder = new Kechengholder(View.inflate(context, R.layout.course_item, null));
        return kechengholder;
    }

    @Override
    public void onBindViewHolder(Kechengholder holder, int position) {
        Course course = list.get(position);
        holder.textView_title.setText(course.getTitle());
        holder.textView_title2.setText(course.getTitle2());
        holder.teacher_name.setText(course.getSpeaker());
        holder.textView_length.setText(course.getLength()+"");
        holder.textView_money.setText("￥"+course.getPrice()+"小时");
        holder.textView_volume.setText("已售"+course.getVolume());
        String type = course.getType();
        if(type.equals("1")){
            ((Kechengholder) holder).type_imageView.setBackgroundResource(R.drawable.home_listen);
        }else if(type.equals("2")){
            ((Kechengholder) holder).type_imageView.setBackgroundResource(R.drawable.home_watch);
        }
        // Glide.with(context).load(course.getImage()).bitmapTransform(new RoundedCornersTransformation(context,10,0,RoundedCornersTransformation.CornerType.ALL)).crossFade(500).into( holder.imageView);
        //  holder.imageView.setBackgroundResource(list.get(position).getImage());

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class Kechengholder extends RecyclerView.ViewHolder {

       ImageView kecheng_imageView;
        TextView textView_title2;
        TextView textView_title;
         TextView textView_length;
         TextView textView_money;
         TextView textView_volume;
       TextView teacher_name;
         ImageView type_imageView;

        public Kechengholder(View itemView) {
            super(itemView);
            type_imageView = (ImageView) itemView.findViewById(R.id.type_imageView);
            teacher_name = (TextView) itemView.findViewById(R.id.course_teacher_name);
            kecheng_imageView = (ImageView) itemView.findViewById(R.id.kecheng_imageView);
            textView_title = (TextView) itemView.findViewById(R.id.kecheng_title);
            textView_title2 = (TextView) itemView.findViewById(R.id.kecheng_title2);
            textView_length = (TextView) itemView.findViewById(R.id.kecheng_length);
            textView_money = (TextView) itemView.findViewById(R.id.kecheng_money);
            textView_volume = (TextView) itemView.findViewById(R.id.kecheng_volume);
        }
    }
}
